package com.spa.infrastructure.repository.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spa.infrastructure.repository.mapper.RoleMenuRefMapper;
import com.spa.infrastructure.repository.po.RoleMenuRefPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RoleMenuRefRepositoryService extends ServiceImpl<RoleMenuRefMapper, RoleMenuRefPO> {

    @Autowired
    private RoleMenuRefMapper roleMenuRefMapper;

    public int add(RoleMenuRefPO po) {
        return roleMenuRefMapper.insert(po);
    }

    public void deleteByRoleId(long roleId) {
        QueryWrapper<RoleMenuRefPO> wrapper = Wrappers.query();
        wrapper.eq("role_id", roleId);
        roleMenuRefMapper.delete(wrapper);
    }

    public List<RoleMenuRefPO> listByRoleId(long roleId) {
        QueryWrapper<RoleMenuRefPO> wrapper = Wrappers.query();
        wrapper.eq("role_id", roleId);
        return list(wrapper);
    }

}
